<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function ajax(url,data,method="get"){
            return new Promise((res,rej)=>{
                // ['c=a','b=f']
                let str = Object.keys(data).map(item=>`${item}=${data[item]}`).join('&');
                let x =new XMLHttpRequest();
                if(method === 'get'){
                    x.open(method,url+'?'+str)
                    x.send()
                }
                if(method==='post'){
                    x.open(method,url)
                    x.send(str)
                }
                x.responseType = 'json';
                x.onreadystatechange = function(){
                    if(x.readyState === 4){
                        if(x.status>=200 && x.status<300){
                            res(x.response)
                        }else{
                            rej(x.statusText)
                        }
                    }
                }
            })
        }

       (async function(){
           let res = await ajax('https://v1.hitokoto.cn',{c:"c",b:"f"});
           console.log(res.hitokoto);
       })()

       console.log("end");


        // let p = ajax('https://v1.hitokoto.cn/?c=a');

        // // console.log(p);
        // p.then(val=>{
        //     let obj = JSON.parse(val)

        //     console.log(obj.hitokoto);
        // })

    </script>
</body>
</html>